package com.efuture.mutlithread;

/**
 * @ClassNAME ThreadStopTest
 * @Description 强行终止一个线程
 * @Author zhaoshanshan
 * @Date 2021/9/10 12:21 上午
 * @Version 1.0
 */
public class ThreadStopTest {
    public static void main(String[] args) {
        SonThreadStopTest t = new SonThreadStopTest();
        t.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t.stop();//强制终止t线程 不建议使用，这个方法会直接把线程杀死，线程数据没有保存，容易丢失数据
    }
}
class SonThreadStopTest extends Thread{
    @Override
    public void run() {
        for (int i=0;i<10;i++){
            System.out.println(i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}